package com.example.exam.ZhangFengHua;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.example.exam.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Introduction extends Fragment {
    @BindView(R.id.lvfruits)
    ListView lvfruits;
//    private String[] data = {"Apple", "Banana", "Orange", "Watermelon", "pear"};
    private List<Fruits_list>fruits_lists=new ArrayList<>();
    public Introduction() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.introduction, container, false);
        ButterKnife.bind(this,view);
        initView();
        Fruits_Adapter adapter=new Fruits_Adapter(getContext(),R.layout.text,fruits_lists);
        lvfruits.setAdapter(adapter);
        return view;
    }
    private void initView(){
            Fruits_list apple=new Fruits_list("Apple",R.mipmap.ic_launcher);fruits_lists.add(apple);
            Fruits_list banana=new Fruits_list("Banana",R.mipmap.ic_launcher);fruits_lists.add(banana);
            Fruits_list orange=new Fruits_list("Orange",R.mipmap.ic_launcher);fruits_lists.add(orange);
            Fruits_list watermelon=new Fruits_list("Watermelon",R.mipmap.ic_launcher);fruits_lists.add(watermelon);
            Fruits_list pear=new Fruits_list("Pear",R.mipmap.ic_launcher);fruits_lists.add(pear);
            lvfruits.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    Fruits_list fruits_list=fruits_lists.get(i);
                    Toast.makeText(getContext(), fruits_list.getName(), Toast.LENGTH_SHORT).show();
                }
            });
    }
}
